poshidprobs_guess = 1./(1 + exp(-rate_matrix*vishid - repmat(hidbiases,size(rate_matrix,1),1)));    

negdata_guess = poshidprobs_guess*vishid' + repmat(visbiases,size(rate_matrix,1),1);
  
%{
tmpsum = 0;
for m = 0:size(negdata_guess,2)/5-1
    for n = 1:size(rate_matrix,1)
        tmpsum = max(negdata_guess(n,m*5+1:m*5+5));
        negdata_guess(n,m*5+1:m*5+5) = exp(negdata_guess(n,m*5+1:m*5+5)-tmpsum);
        tmpsum = sum(negdata_guess(n,m*5+1:m*5+5));
        negdata_guess(n,m*5+1:m*5+5) = negdata_guess(n,m*5+1:m*5+5)/tmpsum;
    end
end
%}

finalresult = zeros(num_users, num_items);
template = [1 2 3 4 5];
for m=1:num_users
    reshap = reshape(negdata_guess(m,:),5, num_items);
    reshap = exp(reshap - repmat(max(reshap), 5, 1));
    reshap = reshap./repmat(sum(reshap), 5, 1);
    %negdata_guess(m,:) = reshape(reshap, 1, 5*num_items);
    finalresult(m,:) = template*reshap;
end
        
finalresult = finalresult.*test_template;
mae = sum(sum(abs(finalresult-test_real_matrix)))/test_size;

%{
for m=1:test_size
    tmp_score = 0.0;
    for n=1:5
        tmp_score  = tmp_score+n*negdata_guess(test_real(m,1),test_real(m,2)*5-5+n);
    end
    mae = mae + abs(tmp_score - test_real(m,3));
end
%}

    
fprintf(1, 'epoch %4i   MAE %6f \n', epoch, mae);

